import jsonpath
import requests

from bazhuayun.utils.log_util import logger


class BaseApi:
    __REQ = {
        "method": "POST",
        "url": "http://api.wxorder.taover.com/login",
        "json": {"username": "17611219803", "password": "Ceba_17611219803", "code": ""},
    }

    def send_api(self, req):
        """
        对 requests 完成二次封装
        :return:
        """
        logger.info(f"请求数据为 {req}")
        r = requests.request(**req)
        logger.info(f"响应体为 {r.text}")
        return r

    def get_token(self):
        r = self.send_api(self.__REQ)
        token = jsonpath.jsonpath(r.json(), "$..token")[0]
        return token



